home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
IRIX Base Documentation 1998 November
/
IRIX 6.5.2 Base Documentation November 1998.img
/
usr
/
share
/
catman
/
u_man
/
cat1
/
grep.z
/
grep
Wrap
Text File
|
1998-10-20
|
15KB
|
331 lines
GGGGRRRREEEEPPPP((((1111)))) GGGGRRRREEEEPPPP((((1111))))
NNNNAAAAMMMMEEEE
_gggg_rrrr_eeee_pppp - search a file for a pattern
SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
_gggg_rrrr_eeee_pppp [_----_EEEE| _----_FFFF] [_----_cccc| _----_llll| _----_qqqq] [_----_iiii_nnnn_ssss_vvvv_xxxx] _----_eeee _p_a_t_t_e_r_n__l_i_s_t[_----_ffff _p_a_t_t_e_r_n__f_i_l_e]. .
.[_f_i_l_e . . .]
_gggg_rrrr_eeee_pppp [_----_EEEE| _----_FFFF] [_----_cccc| _----_llll| _----_qqqq] [_----_iiii_nnnn_ssss_vvvv_xxxx][_----_eeee _p_a_t_t_e_r_n__l_i_s_t_----_ffff _p_a_t_t_e_r_n__f_i_l_e]. .
.[_f_i_l_e . . .]
_gggg_rrrr_eeee_pppp [_----_EEEE| _----_FFFF] [_----_cccc| _----_llll| _----_qqqq] [_----_iiii_nnnn_ssss_vvvv_xxxx] _p_a_t_t_e_r_n__l_i_s_t[_f_i_l_e . . .]
DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
The _g_r_e_p utility searches the input files, selecting lines matching one
or more patterns; the types of patterns are controlled by the options
specified. The patterns are specified by the _----_eeee option, _----_ffff option, or
the _p_a_t_t_e_r_n__l_i_s_t operand. The _p_a_t_t_e_r_n__l_i_s_t's value consists of one or
more patterns separated by newline characters; the _p_a_t_t_e_r_n__f_i_l_e's
contents consist of one or more patterns terminated by newline
characters. By default, an input line will be selected if any pattern,
treated as an entire basic regular expression (BRE) as described in the
_rrrr_eeee_gggg_cccc_oooo_mmmm_pppp(5) man page under the section titled: _B_a_s_i_c _R_e_g_u_l_a_r _E_x_p_r_e_s_s_i_o_n_s,
matches any part of the line; a null BRE will match every line. By
default, each selected input line will be written to the standard output.
Regular expression matching will be based on text lines. Since a newline
character separates or terminates patterns (see the _----_eeee and _----_ffff options
below), regular expressions cannot contain a newline character.
Similarly, since patterns are matched against individual lines of the
input, there is no way for a pattern to match a newline character found
in the input.
Command line options are:
_----_EEEE Match using extended regular expressions. Treat each pattern
specified as an ERE, as described in the _rrrr_eeee_gggg_cccc_oooo_mmmm_pppp(5) man page
under the section titled: _E_x_t_e_n_d_e_d _R_e_g_u_l_a_r _E_x_p_r_e_s_s_i_o_n_s. If any
entire ERE pattern matches an input line, the line will be
matched. A null ERE matches every line.
_----_FFFF Match using fixed strings. Treat each pattern specified as a
string instead of a regular expression. If an input line contains
any of the patterns as a contiguous sequence of bytes, the line
will be matched. A null string matches every line.
_----_cccc Write only a count of selected lines to standard output.
_----_eeee _p_a_t_t_e_r_n__l_i_s_t
Specify one or more patterns to be used during the search for
input. Patterns in _p_a_t_t_e_r_n__l_i_s_t must be separated by a newline
character. A null pattern can be specified by two adjacent
PPPPaaaaggggeeee 1111
GGGGRRRREEEEPPPP((((1111)))) GGGGRRRREEEEPPPP((((1111))))
newline characters in _p_a_t_t_e_r_n__l_i_s_t. Unless the _----_EEEE or _----_FFFF option is
also specified, each pattern will be treated as a BRE, as
described in the _rrrr_eeee_gggg_cccc_oooo_mmmm_pppp(5) man page under the section titled:
_B_a_s_i_c _R_e_g_u_l_a_r _E_x_p_r_e_s_s_i_o_n_s. Multiple _----_eeee and _----_ffff options are
accepted by the _g_r_e_p utility. All of the specified patterns are
used when matching lines, but the order of evaluation is
unspecified.
_----_ffff _p_a_t_t_e_r_n__f_i_l_e
Read one or more patterns from the file named by the pathname
pattern_file. Patterns in _p_a_t_t_e_r_n__f_i_l_e are terminated by a
newline character. A null pattern can be specified by an empty
line in _p_a_t_t_e_r_n__f_i_l_e. Unless the _----_EEEE or _----_FFFF option is also
specified, each pattern will be treated as a BRE, as described in
the _rrrr_eeee_gggg_cccc_oooo_mmmm_pppp(5) man page under the section titled: _B_a_s_i_c _R_e_g_u_l_a_r
_E_x_p_r_e_s_s_i_o_n_s.
_----_iiii Perform pattern matching in searches without regard to case. See
the _rrrr_eeee_gggg_cccc_oooo_mmmm_pppp(5) man page under the section titled: _R_e_g_u_l_a_r
_E_x_p_r_e_s_s_i_o_n _G_e_n_e_r_a_l _R_e_q_u_i_r_e_m_e_n_t_s.
_----_llll Write only the names of files containing selected lines to
standard output. Pathnames are written once per file searched.
If the standard input is searched, a pathname of "(_ssss_tttt_aaaa_nnnn_dddd_aaaa_rrrr_dddd
_iiii_nnnn_pppp_uuuu_tttt)" will be written, in the POSIX locale. In other locales,
_ssss_tttt_aaaa_nnnn_dddd_aaaa_rrrr_dddd _iiii_nnnn_pppp_uuuu_tttt may be replaced by something more appropriate in
those locales.
_----_nnnn Precede each output line by its relative line number in the file,
each file starting at line 1. The line number counter will be
reset for each file processed.
_----_qqqq Quiet. Do not write anything to the standard output, regardless
of matching lines. Exit with zero status if an input line is
selected.
_----_ssss Suppress the error messages ordinarily written for non-existent
or unreadable files. Other error messages will not be suppressed.
_----_vvvv Select lines not matching any of the specified patterns. If the
_----_vvvv option is not specified, selected lines will be those that
match any of the specified patterns.
_----_xxxx Consider only input lines that use all characters in the line to
match an entire fixed string or regular expression to be matching
lines.
OOOOPPPPEEEERRRRAAAANNNNDDDDSSSS
The following operands are supported:
PPPPaaaaggggeeee 2222
GGGGRRRREEEEPPPP((((1111)))) GGGGRRRREEEEPPPP((((1111))))
_p_a_t_t_e_r_n
Specify one or more patterns to be used during the search for input.
This operand is treated as if it were specified as _----_eeee _p_a_t_t_e_r_n__l_i_s_t.
_f_i_l_e A pathname of a file to be searched for the patterns. If no _f_i_l_e
operands are specified, the standard input will be used.
SSSSTTTTDDDDIIIINNNN
The standard input will be used only if no _f_i_l_e operands are specified.
See _IIII_NNNN_PPPP_UUUU_TTTT _FFFF_IIII_LLLL_EEEE_SSSS.
IIIINNNNPPPPUUUUTTTT FFFFIIIILLLLEEEESSSS
The input files must be text files.
SSSSTTTTDDDDOOOOUUUUTTTT
If the _----_llll option is in effect, and the _----_qqqq option is not, the following
will be written for each file containing at least one selected input
line:
"%s\n", _f_i_l_e
Otherwise, if more than one _f_i_l_e argument appears, and _----_qqqq is not
specified, the _g_r_e_p utility will prefix each output line by:
"%s:", _f_i_l_e
The remainder of each output line depends on the other options specified:
_oooo If the _----_cccc option is in effect, the remainder of each output line will
contain:
"%d\n", <_c_o_u_n_t>
_oooo Otherwise, if _----_cccc is not in effect and the _----_nnnn option is in effect, the
following will be written to standard output:
"%d:", <_l_i_n_e _n_u_m_b_e_r>
_oooo Finally, the following will be written to standard output:
"%s", <_s_e_l_e_c_t_e_d-_l_i_n_e _c_o_n_t_e_n_t_s>
SSSSTTTTDDDDEEEERRRRRRRR
Used only for diagnostic messages.
PPPPaaaaggggeeee 3333
GGGGRRRREEEEPPPP((((1111)))) GGGGRRRREEEEPPPP((((1111))))
SEE ALSO
_eeee_dddd(1), _eeee_gggg_rrrr_eeee_pppp(1), _ffff_gggg_rrrr_eeee_pppp(1), _rrrr_eeee_gggg_cccc_oooo_mmmm_pppp(5), _ssss_eeee_dddd(1), _ssss_hhhh(1)
EEEEXXXXIIIITTTT SSSSTTTTAAAATTTTUUUUSSSS
Exit status is 0 if any matches are found, 1 if none, >1 for syntax
errors or inaccessible files (even if matches were found).
CCCCOOOONNNNSSSSEEEEQQQQUUUUEEEENNNNCCCCEEEESSSS OOOOFFFF EEEERRRRRRRROOOORRRRSSSS
If the _----_qqqq option is specified, the exit status will be zero if an input
line is selected, even if an error was detected.
If the requested action cannot be performed on a file, _gggg_rrrr_eeee_pppp will issue a
diagnostic message to standard error and continue processing the next
operand in sequence, but the final exit status is returned as non-zero.
AAAAPPPPPPPPLLLLIIIICCCCAAAATTTTIIIIOOOONNNN UUUUSSSSAAAAGGGGEEEE
Care should be taken when using characters in _p_a_t_t_e_r_n__l_i_s_t that may also
be meaningful to the command interpreter. It is safest to enclose the
entire _p_a_t_t_e_r_n__l_i_s_t argument in single quotes:
The _----_eeee _p_a_t_t_e_r_n__l_i_s_t option has the same effect as the _p_a_t_t_e_r_n__l_i_s_t
operand, but is useful when _p_a_t_t_e_r_n__l_i_s_t begins with the hyphen
delimiter. It is also useful when it is more convenient to provide
multiple patterns as separate arguments.
Multiple _----_eeee and _----_ffff options are accepted and _g_r_e_p will use all of the
patterns it is given while matching input text lines. (Note that the
order of evaluation is not specified. If an implementation finds a null
string as a pattern, it is allowed to use that pattern first, matching
every line, and effectively ignore any other patterns.)
The _----_qqqq option provides a means of easily determining whether or not a
pattern (or string) exists in a group of files. When searching several
files, it provides a performance improvement (because it can quit as soon
as it finds the first match) and requires less care by the user in
choosing the set of files to supply as arguments (because it will exit
zero if it finds a match even if _g_r_e_p detected an access or read error on
earlier file operands).
EEEEXXXXAAAAMMMMPPPPLLLLEEEESSSS
1. To find all uses of the word Posix in a bunch of files where some of
the files cannot be opened due to permission restrictions:
_g_r_e_p -_q -_n _P_o_s_i_x /_e_t_c/*
Note the above use of the -_q command line option to _g_r_e_p. If the -_q
is not used in the above command line, then when the first file is
encountered that is not readable _g_r_e_p will error terminate even if
there were some matches found.
PPPPaaaaggggeeee 4444
GGGGRRRREEEEPPPP((((1111)))) GGGGRRRREEEEPPPP((((1111))))
2. To find all uses of the word Posix (in any case) in file _tttt_eeee_xxxx_tttt_...._mmmm_mmmm and
write with line numbers:
_g_r_e_p -_i -_n _p_o_s_i_x _t_e_x_t._m_m
3. To find all empty lines in the standard input:
_g_r_e_p $
or:
_g_r_e_p -_v
4. Both of the following commands print all lines containing strings
_aaaa_bbbb_cccc or _dddd_eeee_ffff or both:
_g_r_e_p -_E '_a_b_c
_d_e_f'
_g_r_e_p -_F '_a_b_c
_d_e_f'
5. Both of the following commands print all lines matching exactly _aaaa_bbbb_cccc
or _dddd_eeee_ffff:
_g_r_e_p -_E '_a_b_c$
^_d_e_f$'
_g_r_e_p -_F -_x '_a_b_c
_d_e_f'
BBBBUUUUGGGGSSSS
If there is a line with embedded nulls, _gggg_rrrr_eeee_pppp will only match up to the
first null; if it matches, it will print the entire line.
PPPPaaaaggggeeee 5555